define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mall/user/favorite/index',
                    add_url: 'mall/user/favorite/add',
                    edit_url: 'mall/user/favorite/edit',
                    del_url: 'mall/user/favorite/del',
                    multi_url: 'mall/user/favorite/multi',
                    table: 'mall_user_favorite',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'type', title: __('Type'), searchList: {"goods":__('Goods'),"shop":__('Shop'),"article":__('Article'),"cms_news":__('Cms_news'),"cms_product":__('Cms_product'),"cms_download":__('Cms_download'),"outlink":__('Outlink')}, formatter: Table.api.formatter.normal},
                        {field: 'target', title: __('Target')},
                        {field: 'title', title: __('Title'), visible:false},
                        {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, visible:false},
                        {field: 'tags', title: __('Tags'), visible:false},
                        {field: 'status', title: __('Status'), searchList: {"open":__('Status open'),"friend":__('Status friend'),"private":__('Status private')}, formatter: Table.api.formatter.status, visible:false},
                        {field: 'createtime', title: __('Create time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});